package controll;

import java.sql.Date;
import java.util.List;

import model.ChiTietHoaDon;
import model.Ga;
import model.Ghe;
import model.Tau;
import model.Toa;

public class Controller {
	
	private Mapping map  = null;
	
	public List<Ghe> getListGheTrong(Tau tau,Date ngay, Ga gaDi, Ga gaDen) {
		map = new Mapping();
		List<Ghe> listGheTrong = null;
		List<Toa> listToa  = map.getListToa(tau);
		for (Toa toa : listToa) {
			listGheTrong.addAll(map.getGheList(toa));
		} 
		for (Ghe ghe : listGheTrong) {
			List<ChiTietHoaDon> listCTHD = map.getListCTHD(tau, ghe, ngay);
			if(gaDi.getGaID() < gaDen.getGaID()) {
				for (ChiTietHoaDon chiTietHoaDon : listCTHD) {
					if(!(chiTietHoaDon.getGaDi().getGaID() > gaDen.getGaID() && chiTietHoaDon.getGaDen().getGaID() < gaDi.getGaID())) {
						listGheTrong.remove(ghe);
						break;
					}
				}
			} else {
				for (ChiTietHoaDon chiTietHoaDon : listCTHD) {
					if(!(chiTietHoaDon.getGaDi().getGaID() < gaDen.getGaID() && chiTietHoaDon.getGaDen().getGaID() > gaDi.getGaID())) {
						listGheTrong.remove(ghe);
						break;
					}
				}
			}
			
		}
		
		return listGheTrong;
		
	}
}
